package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.EventListData;

import java.util.List;

/**
 * Created by Megan on 15/9/6.
 */
public class EventSendGridAdapter extends BaseAdapter {

    private Context mContext;
    private List<EventListData> mResultData;

    public EventSendGridAdapter(Context context, List<EventListData> mResultData) {
        this.mContext = context;
        this.mResultData = mResultData;
    }

    @Override
    public int getCount() {
        return mResultData.size();
    }

    @Override
    public Object getItem(int position) {
        return mResultData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        EventListData EventListData = mResultData.get(position);
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.send_event_item, null);
            holder.img = (ImageView) convertView.findViewById(R.id.iv_send_event_img);
            holder.name = (TextView) convertView.findViewById(R.id.tv_send_event_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (EventListData.getEventTitleHead() != -1){
            holder.img.setImageDrawable(mContext.getResources().getDrawable(EventListData.getEventTitleHead()));
            holder.name.setText(EventListData.getEventName());
        }
        return convertView;
    }

    private class ViewHolder {
        ImageView img;
        TextView name;
    }


}
